package com.weyoung.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.weyoung.app.mapper.DeviceStatsMapper;
import com.weyoung.app.service.DeviceStatsService;
import com.weyoung.entity.DeviceStats;
import org.springframework.stereotype.Service;

@Service
public class DeviceStatsServiceImpl extends ServiceImpl<DeviceStatsMapper, DeviceStats> implements DeviceStatsService {
    
    @Override
    public void saveOrUpdateStats(DeviceStats stats) {
        LambdaQueryWrapper<DeviceStats> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DeviceStats::getUrl, stats.getUrl())
                .eq(DeviceStats::getUserId, stats.getUserId())
                .eq(DeviceStats::getDate, stats.getDate())
                .eq(DeviceStats::getDevice, stats.getDevice());
        
        DeviceStats existing = this.getOne(wrapper);
        if (existing == null) {
            this.save(stats);
        }
    }
} 